#%%
import akshare as ak
from DataGeter import inputfomating

"""
RealTime() 返回指数数据
Divided_detial_total() 返回分红总体情况
stock_info(date) 市场公告,停牌复牌
Divided_detial_single(code, date) 返回个股的具体分红情况和日期

akmins(code)
"""
#%%
def RealTime():
    """
    返回指数数据
    """
    stock_df = ak.stock_zh_index_spot()
    return stock_df


def Divided_detial_total():
    """
    全部分红信息
    """
    stock_history_dividend_df = ak.stock_history_dividend()
    return stock_history_dividend_df


def Divided_detial_single(code, date):
    """
    个股分红具体信息
    date = '2019-07-08'
    """
    code = inputfomating.codeFormating(code)
    start = inputfomating.dateFormating(start, mode="L")

    stock_history_dividend_detail_df = ak.stock_history_dividend_detail(
        indicator="分红", stock=code, date=date
    )
    return stock_history_dividend_detail_df


def stock_info(date):
    """
    停牌复牌信息
    date = '2019-07-08'
    """
    code = inputfomating.codeFormating(code)
    date = inputfomating.dateFormating(date, mode="L")
    stock_em_tfp_df = ak.stock_em_tfp(trade_date=date)
    return stock_em_tfp_df


def akmins(code):
    """
    akmins('sh601398') 返回2号到7号数据
    """
    code = inputfomating.codeFormating(code)
    stock_zh_a_minute_df = ak.stock_zh_a_minute(
        symbol=code, period="60", adjust="qfq"
    )  # adjust="qfq" 则返回前复权后的数据，默认 adjust="", 则返回未复权的数据
    return stock_zh_a_minute_df


def ak_daily(code, start, end):
    """
    code = "sz000002"
    start = '20201103'
    end = '20201116'
    """
    df = ak.stock_zh_a_daily(symbol=code, start_date=start, end_date=end, adjust="qfq")
    return df


def aktickertx(code, date, sorce="tx"):
    """
    模块有问题，暂时无法使用
    code: sh600848"
    date: date
    注意腾讯不太好获取数据 Ticker
    """
    # TODO 16.00 以后再试一次
    code = inputfomating.codeFormating(code)
    date = inputfomating.dateFormating(date, mode="L")
    if sorce == "tx":
        stock_zh_a_tick_df = ak.stock_zh_a_tick_tx(code=code, trade_date=date)

    elif sorce == "163":
        stock_zh_a_tick_df = ak.stock_zh_a_tick_163(code=code, trade_date=date)

    return stock_zh_a_tick_df


#%%
#  TODO 等待修复
def analysit():
    """
    交易员个人信息，当年涨跌幅，3月6月12月总计涨跌幅
    """
    stock_em_analyst_rank_df = ak.stock_em_analyst_rank()
    return stock_em_analyst_rank_df


def akAnalystDetail(analyst_id):
    """
    输入交易员ID，返回详情
    analysitInfor().akAnalystDetail()
    """
    stock_em_analyst_detail_df = ak.stock_em_analyst_detail(
        analyst_id=analyst_id, indicator="最新跟踪成分股"
    )
    return stock_em_analyst_detail_df


#%%
def gpzy_pledge_ratio(date):
    """
    股权质押市场概况
    date = 2020-12-20
    """
    date = inputfomating.dateFormating(date, mode="L")
    df = ak.stock_em_gpzy_pledge_ratio(trade_date=date)
    return df


def gpzy_pledge_ratio_detail():
    """
    上市公司质押比例
    """
    df = ak.stock_em_gpzy_pledge_ratio_detail()
    return df


def gpzy_distribute_statistics_company():
    """
    质押机构分布统计证券公司
    """
    df = ak.stock_em_gpzy_distribute_statistics_company()
    return df


def gpzy_distribute_statistics_company():
    """
    质押机构分布统计银行
    """
    df = ak.stock_em_gpzy_distribute_statistics_bank()
    return df


def gpzy_industry_data():
    """
    上市公司质押比例
    """
    df = ak.stock_em_gpzy_industry_data()
    return df


#%%

if __name__ == "__main__":
    code = 300999
    date = 20190101
    df = aktickertx(code, date, sorce="tx")
    print(df)
    pass
# %%
